import React from 'react';
import { Redirect } from 'umi';
import OpenPageLayout from './OpenPageLayout';
import { isOpenPages } from '../helpers/env';
import AuthRequiredLayout from './AuthRequiredLayout/index';
import { CookieJar } from 'tough-cookie';
interface Iprops {
  location: any;
  route: any;
  children: any;
}

export default function Layout({ location, route, children }: Iprops) {
  console.log(location.pathname);
  if (isOpenPages(location.pathname)) {
    return <OpenPageLayout>{children}</OpenPageLayout>;
  }
  if (checkIfPageExist(route, location)) {
    return <div>{children}</div>;
  }
  return (
    <Redirect
      to={{
        pathname: '/404',
        search: `?from=${encodeURIComponent(location.pathname)}`,
      }}
    />
  );
}

function checkIfPageExist(route: any, location: any) {
  if (!route || !route.routes) {
    return false;
  }
}
